package com.usian.service.impl;

import com.usian.pojo.TbItem;
import com.usian.redis.RedisClient;
import com.usian.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    private RedisClient redisClient;

    @Override
    public Map<String, TbItem> selectCartByUserId(String userId) {

        //从redis取购物车信息  hash
        return (Map<String, TbItem>)redisClient.hget("CART_REDIS_KEY",userId);
    }

    @Override
    public boolean insertItemToRedis(Map<String, TbItem> cart, String userId) {
        boolean bool = redisClient.hset("CART_REDIS_KEY", userId, cart);
        return bool;
    }
}
